package com.valid;

import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.validation.ConstraintViolationException;

@RestControllerAdvice
public class ExcetionHandle {

    @ExceptionHandler(ConstraintViolationException.class)
    public String handle(ConstraintViolationException e) {
        return e.getMessage();
    }

    @ExceptionHandler(BindException.class)
    public String handleEx(BindException e){
        return e.getBindingResult().toString();
    }
}
